#!/usr/bin/env bash

awk_file=tmp.awk
cat >$awk_file <<EOF
END {
    CHARS="0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
# [1,length] split数组下标从1开始
    rand_range=split(CHARS, aCHARS, /,/);
    srand();

    while(rec_count < rec_qt)
    {
        code="";
        for(i=0; i<code_len; ++i)
        {
            code=code aCHARS[int(rand()*rand_range)+1];
        }
        if(code in codes)
        {
            printf("%s duplicate\n", code);
            continue;
        }
        ++rec_count;
        codes[code]=1;
    }
    for(code in codes)
    {
        print code;
    }
}
EOF
codes=( $(awk -f $awk_file code_len=8 rec_qt=100000 /dev/null) )

code_file=code.txt
rm -f $code_file
for v in ${codes[*]}
do
    echo $v >>$code_file
done
